package com.tgy.leetcode;

import java.util.Arrays;

public class _179_最大数 {

    public static String largestNumber(int[] nums) {

        int len = nums.length;
        Integer[] integers = new Integer[len];

        for (int i = 0; i < len; i++) {

            integers[i] = nums[i];
        }

        Arrays.sort(integers,(x,y)->{

            long one = 10,two = 10;

            while (one <= x) {

                one *= 10;
            }

            while (two <= y) {

                two *= 10;
            }

            return Long.compare(y*one+x,x*two + y);
        });

        if (integers[0] == 0) {

            return "0";
        }

        StringBuilder sb = new StringBuilder();

        for (Integer integer : integers) {

            sb.append(integer);
        }

        return sb.toString();
    }

    public static void main(String[] args) {

//        int[] nums = {3,31,33,30,34,5,9};
        int[] nums = {0,0};
//        int[] nums = {999999998,999999997,999999999};
        System.out.println(largestNumber(nums));
    }
}
